/*
 * Copyright 2009 Gal Dolber
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.user.dragdrop.client.impl;

import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.user.dragdrop.client.DragController;
import com.google.gwt.user.dragdrop.client.ResizeController;

/**
 * Resize fixed width and height
 */
public class ResizeFixedImpl extends ResizeImpl {
	private void ensureHeight(ResizeController controller) {
		int width = controller.getWidth();
		controller.setWidgetHeight(width);
	}

	private void ensureWidth(ResizeController controller) {
		int height = controller.getHeight();
		controller.setWidgetWidth(height);
	}

	@Override
	public void onResize(ResizeController controller,
			DragController mouseController) {

		super.onResize(controller, mouseController);

		// Only with LEFT button
		if (mouseController.getButton() != NativeEvent.BUTTON_LEFT) {
			return;
		}

		switch (controller.getTargetBorder()) {
		case TOPLEFT:
			ensureWidth(controller);
			break;
		case TOPCENTER:
			ensureWidth(controller);
			break;
		case TOPRIGHT:
			ensureWidth(controller);
			break;
		case CENTERLEFT:
			ensureHeight(controller);
			break;
		case CENTERRIGHT:
			ensureHeight(controller);
			break;
		case BOTTOMLEFT:
			ensureWidth(controller);
			break;
		case BOTTOMCENTER:
			ensureWidth(controller);
			break;
		case BOTTOMRIGHT:
			ensureWidth(controller);
			break;
		case CENTERCENTER:
			ensureWidth(controller);
			break;
		case INVALID:
			break;
		}
	}
}